package com.song.estore.action;

import com.opensymphony.xwork2.ActionContext;
import com.song.estore.domain.User;
import com.song.estore.service.UserService;

/**
 * Created by 范姣姣 on 2015/10/22.
 *
 */
public class RegistAction {


    private String email;
    private String nickname;
    private String password;
    private String repassword;
    private String checkImg;
    private String msg;

    private UserService userService;


    public String execute(){

        String key = (String) ActionContext.getContext().getSession().get("key");

        if( checkImg == null || checkImg.trim().length() <= 0 || !checkImg.equalsIgnoreCase(key) ){
            msg = "验证码出错，请重试";
            return "error";
        }
        if( email == null || email.trim().length() <= 0  ){

            msg = "用户名不能为空，请重试";
            return "error";
        }
        if( password == null || repassword == null || !password.equals(repassword)  ){
            msg = "密码不能为空或两次密码不一致，请重试";
            return "error";
        }
        User u = new User();
        u.setEmail(email);
        u.setNickname(nickname);
        u.setPassword(password);

        if(userService.addUser(u))
            return "success";

        msg = "插入数据出错";
        return "error";
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRepassword() {
        return repassword;
    }

    public void setRepassword(String repassword) {
        this.repassword = repassword;
    }

    public String getCheckImg() {
        return checkImg;
    }

    public void setCheckImg(String checkImg) {
        this.checkImg = checkImg;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
